﻿using System;
using System.Collections.Generic;
using System.Runtime.Serialization;
using System.Security.Permissions;
using System.Text;
using T.ServiceComponent.Error;

namespace T.FAS.Runtime.Metadata.Entity.ScheduleJob
{
    /// <summary>
    /// ScheduleJob异常
    /// </summary>
    [Serializable]
    public class ScheduleJobException : TException
    {
        /// <summary>
        /// 构造函数
        /// </summary>
        /// <param name="exceptionCode">异常编号</param>
        /// <param name="level">异常级别</param>
        public ScheduleJobException(string exceptionCode, TExceptionLevel level = TExceptionLevel.Error)
            : base(exceptionCode)
        {

        }

        /// <summary>
        /// 构造函数
        /// </summary>
        /// <param name="exceptionCode">异常编号</param>
        /// <param name="message">异常信息</param>
        /// <param name="level">异常级别</param>
        public ScheduleJobException(string exceptionCode, string message, TExceptionLevel level = TExceptionLevel.Error)
            : base(exceptionCode)
        {

        }

        /// <summary>
        /// 构造函数
        /// </summary>
        /// <param name="exceptionCode">异常编号</param>
        /// <param name="message">异常信息</param>
        /// <param name="level">异常级别</param>
        public ScheduleJobException(string exceptionCode, string message, Exception innnerException, TExceptionLevel level = TExceptionLevel.Error)
            : base(exceptionCode, innnerException)
        {

        }

        /// <summary>
        /// 构造函数
        /// </summary>
        /// <param name="info">序列化信息</param>
        /// <param name="context">上下文</param>
        protected ScheduleJobException(SerializationInfo info, StreamingContext context)
            : base(info, context)
        {
            this.Code = info.GetString("ExceptionCode");
            this.Level = (TExceptionLevel)info.GetSingle("Level");
        }

        /// <summary>
        /// 获取对象数据
        /// </summary>
        /// <param name="info">序列化信息</param>
        /// <param name="context">上下文</param>
        [SecurityPermissionAttribute(SecurityAction.Demand, SerializationFormatter = true)]
        public override void GetObjectData(SerializationInfo info, StreamingContext context)
        {
            info.AddValue("ExceptionCode", this.Code);
            info.AddValue("Level", this.Level);

            base.GetObjectData(info, context);
        }
    }
}
